package cn.wolfcode.wechat.controller;

import cn.wolfcode.wechat.util.AccessTokenUtil;
import cn.wolfcode.wechat.util.HttpUtil;
import cn.wolfcode.wechat.vo.TemplateValueVo;
import cn.wolfcode.wechat.vo.TemplateVo;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 季节 on 2017/12/30
 */
/*
* {{result.DATA}} 亲爱的顾客,您本次购买的服务信息如下:
* 打手人数:{{fighterNum.DATA}}
* 打手级别:{{fighterLev.DATA}}
* 服务时间:{{serveTime.DATA}}
* 服务地点:{{serveLocation.DATA}}
* {{remark.DATA}}
* */
@Controller
public class TemplateController {


    @RequestMapping("/template")
    @ResponseBody
    public static TemplateVo template(){
        TemplateVo templateVo = new TemplateVo();
        templateVo.setTemplate_id("NvIkv2FWOfJm-HBXgRN3-cXtq72iA_aS7lapWl6fTY0");
        templateVo.setTouser("ofH1h0pD-ZEiKMpu8F0JumXhviEo");
        templateVo.setUrl("");
        Map<String,TemplateValueVo> data = new HashMap<>();
        data.put("fighterNum",new TemplateValueVo("","#173177"));
        data.put("fighterLev",new TemplateValueVo("","#173177"));
        data.put("serveTime",new TemplateValueVo( new Date().toLocaleString(),"#173177"));
        data.put("serveLocation",new TemplateValueVo("","#173177"));
        data.put("remark",new TemplateValueVo(" 打不死,再打一次 ヾ(◍°∇°◍)ﾉﾞ","#F4A460"));
        templateVo.setData(data);
        //获取access_token


        String access_token = AccessTokenUtil.getAccessTokenVo();


        String accesstoken = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+ access_token;

        HttpUtil.post(accesstoken,JSON.toJSONString(templateVo));

        return templateVo;
    }

    public static void robotfight(String fromUserName){
        TemplateVo templateVo = new TemplateVo();
        templateVo.setTemplate_id("AwDBhrrtpYDiynklFNGK9Do4Iqny5R3KOpNx5WghuW8");
        templateVo.setTouser(fromUserName);
        templateVo.setUrl("");
        Map<String,TemplateValueVo> data = new HashMap<>();
        data.put("fighterNum",new TemplateValueVo("    ┗|｀O′|┛ 嗷~~","#F4A460"));
        data.put("fighterLev",new TemplateValueVo("     X﹏X","#FF8C00"));
        data.put("serveTime",new TemplateValueVo( "  _(:з)∠)_","#FF7F50"));
        data.put("remark",new TemplateValueVo("        ┏┛墓┗┓(m -__-)m","#FF6347"));
        templateVo.setData(data);
        //获取access_token
        String access_token = AccessTokenUtil.getAccessTokenVo();
        String accesstoken = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+ access_token;
        HttpUtil.post(accesstoken,JSON.toJSONString(templateVo));

    }

}
